<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>扩展的对象功能</title>
</head>
<body>
  
</body>

<script type="text/javascript">
  
  // es6直接写入变量和函数，作为对象的属性和方法
  const name = 'chengjunyu', age = 30

  const person = {
    // name: name,
    // age: age
    name,
    age,
    sayName() {
      console.log(name, age)
    }
  }
  person.sayName()

  function fn(x, y) {
    return {x, y}
  }
  console.log(fn(1, 2))

  let car = {
    wheel: 4,
    set(newVal) {
      if (newVal < 4) {
        throw new Error('轮子数太少了')
      }
      this.wheel = newVal
    },
    get() {
      return this.wheel
    }
  }
  car.set(5)
  console.log(car.get())

  
  const obj = {}
  obj.isShow = true
  const obj_name = 'a'
  obj[obj_name + 'bc'] = 123
  console.log(obj)


  // 对象的方法
  // 1、is() ===:比较两个值是否严格相等
  console.log('1' === 1);
  console.log(NaN === NaN);
  console.log(Object.is(NaN, NaN));


  // 2、assign():对象合并
  let newObj =  {d: 0}
  Object.assign(newObj, {a:1, b:2}, {c:3})
  console.log(newObj);

</script>
</html>